import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Enumeration;
@WebServlet("/requestServlet02")
public class RequestServlet02 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req,
                           HttpServletResponse resp) {
        String contentType = req.getContentType();
        String contentType2 = req.getHeader("content-type");
        System.out.println("getContentType()方法获取content-Type字段的值:" + contentType);
        System.out.println("getHeader方法获取content-Type字段的值:" + contentType2);
        System.out.println("所有请求字段的名称和对应值:");
        Enumeration<String> headerNames = req.getHeaderNames();
        while (headerNames.hasMoreElements()){
            String s = headerNames.nextElement();
            System.out.println(s + ":" + req.getHeader(s));
        }
        System.out.println("---------------------------");
        String encoding = req.getCharacterEncoding();
        System.out.println("请求的字符编码:" + encoding);
    }
}
